#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long LL;
const int MAXN=5e5+5,MAXM=1e6+5;
vector<int> vec[MAXN];
int n,dx[MAXM],ti[MAXM],cx;
struct node {
	int x,k;
	friend bool operator<(node a,node b) {return a.x<b.x;} 
}a[MAXM];int cnt;
int c,b[MAXM],d[MAXM],tot;
LL ans,sum;int rot;
signed main() {
	freopen("list.in","r",stdin);
	freopen("list.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;++i) {
		int m;cin>>m;
		vec[i].resize(m),rot+=m;
		for(int j=0;j<m;++j) {
			cin>>vec[i][j];
			dx[++cx]=vec[i][j];
		}
		for(int j=0;j<m-1;++j) b[++tot]=vec[i][j+1]-vec[i][j]+1;
	}
	b[++tot]=1;
	cin>>c;
	for(int i=1;i<=n;++i) cin>>d[i];
	sort(dx+1,dx+1+cx);
	cx=unique(dx+1,dx+1+cx)-dx-1;
	sort(b+1,b+1+tot);
	tot=unique(b+1,b+1+tot)-b-1;
	for(int i=1;i<=n;++i) {
		int m=vec[i].size();
		for(int j=0;j<m;++j) {
			vec[i][j]=lower_bound(dx+1,dx+1+cx,vec[i][j])-dx;
			sum-=1ll*ti[vec[i][j]]*d[ti[vec[i][j]]];
			++ti[vec[i][j]];
			sum+=1ll*ti[vec[i][j]]*d[ti[vec[i][j]]];
		}
		for(int j=0;j<m-1;++j) {
			a[++cnt]=node{dx[vec[i][j+1]]-dx[vec[i][j]]+1,vec[i][j+1]};
		}
	}
	sort(a+1,a+1+cnt);
	LL ans=1e18;
	vector<int> Ans;
	for(int i=1,j=1;i<=tot;++i) {
		// cerr<<b[i]<<" WOC"<<endl;
		while(j<=cnt&&a[j].x==b[i]) {
			sum-=1ll*ti[a[j].k]*d[ti[a[j].k]];
			--ti[a[j].k],--rot;sum+=1ll*(b[i]-1)*c;
			sum+=1ll*ti[a[j].k]*d[ti[a[j].k]];
			++j;
		}
		// cerr<<sum<<' '<<rot<<' '<<sum+1ll*rot*b[i]*c<<" wocatt"<<endl;
		if(ans>sum+1ll*rot*b[i]*c) {
			ans=sum+1ll*rot*b[i]*c;
			Ans.clear();
		}
		if(ans==sum+1ll*rot*b[i]*c) Ans.emplace_back(b[i]);
	}
	cout<<ans<<' '<<Ans.size()<<endl;
	for(auto i:Ans) cout<<i<<' ';
	return 0;
}